<!--
 * @Descripttion: 描述
 * @Author: 刘黎
 * @Date: 2024-06-27 19:40:48
 * @LastEditors: 刘黎
 * @LastEditTime: 2024-08-02 17:32:31
-->
<!-- 新增好友 -->
<template>
  <div class="apption">
    <!-- 标题 -->
    <div class="pageTitle">物流信息</div>
    <div class="topBox">
      <!-- 订单状态((0:代付款,1:待发货,2:已发货,3:已完成,4:已取消,5:售后待审核,6:售后已审核,7:待退款,8:售后完成,9:售后已驳回))  -->
      <el-tabs v-model="prop.status" class="demo-tabs" @tab-click="init()">
        <el-tab-pane label="全部" name=""></el-tab-pane>
        <el-tab-pane label="代付款" name="0"></el-tab-pane>
        <el-tab-pane label="待发货" name="1"></el-tab-pane>
        <el-tab-pane label="已发货" name="2"></el-tab-pane>
        <el-tab-pane label="已完成" name="3"></el-tab-pane>
        <el-tab-pane label="已取消" name="4"></el-tab-pane>
        <el-tab-pane label="售后待审核" name="5"></el-tab-pane>
        <el-tab-pane label="售后已审核" name="6"></el-tab-pane>
        <el-tab-pane label="待退款" name="7"></el-tab-pane>
        <el-tab-pane label="售后完成" name="8"></el-tab-pane>
        <el-tab-pane label="售后已驳回" name="9"></el-tab-pane>
      </el-tabs>
      <div class="searchTop">
        <div class="left">
          <el-form :inline="true" :model="prop" class="demo-form-inline" label-width="100px">
            <el-form-item label="订单编号:">
              <el-input v-model="prop.sn" placeholder="请输入订单编号" />
            </el-form-item>
            <el-form-item label="收件人:">
              <el-input v-model="prop.name" placeholder="请输入收件人" />
            </el-form-item>
            <el-form-item label="选择下单时间:">
              <el-date-picker
                v-model="prop.create_time"
                type="datetime"
                placeholder="选择时间"
                format="YYYY-MM-DD HH:mm:ss"
                value-format="YYYY-MM-DD HH:mm:ss"
                style="width: 180px;"
              />
            </el-form-item>
            <el-form-item label="联系电话:">
              <el-input v-model="prop.phone" placeholder="请输入联系电话" />
            </el-form-item>
            <el-form-item label="选择经销商:">
              <el-select v-model="prop.user_id" clearable placeholder="请选择任务状态" style="min-width: 180px;">
                <el-option v-for="list,index of prop.userOption" :key="index"
                  :label="list.name"
                  :value="list.id"/>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <div class="right">
          <el-button type="primary" @click="init">查询</el-button>
          <el-button type="success" @click="resetClick">重置</el-button>
          <!-- <el-button type="primary" @click="addClick">新增</el-button> -->
        </div>
      </div>
    </div>
    <div class="tableClass">
      <el-table :data="tableData" v-loading="loading" border style="width: 100%">
        <el-table-column type="index" label="序号" width="60" />
        <el-table-column prop="sn" label="订单编号" />
        <el-table-column prop="name" label="收件人" />
        <el-table-column label="商品图片">
          <template #default="scope">
            <el-image :src="scope.row.goods_logo" style="width: 45px;height: 45px;"></el-image>
          </template>
        </el-table-column>
        <el-table-column label="商品状态">
          <template #default="scope">
            <template v-if="scope.row.status===0">代付款</template>
            <template v-if="scope.row.status===1">待发货</template>
            <template v-if="scope.row.status===2">已发货</template>
            <template v-if="scope.row.status===3">已完成</template>
            <template v-if="scope.row.status===4">已取消</template>
            <template v-if="scope.row.status===5">售后待审核</template>
            <template v-if="scope.row.status===6">售后已审核</template>
            <template v-if="scope.row.status===7">待退款</template>
            <template v-if="scope.row.status===8">售后完成</template>
            <template v-if="scope.row.status===9">售后已驳回</template>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="电话" />
        <el-table-column prop="area" label="发货地址" />
        <el-table-column prop="user.name" label="经销商" />
        <el-table-column prop="update_time" label="下单时间" />
        <el-table-column prop="" label="经销商等级">
          <template #default="scope">
            <template v-if="scope.row.user.level===0">无等级</template>
            <template v-if="scope.row.user.level===1">分公司</template>
            <template v-if="scope.row.user.level===2">大批发</template>
            <template v-if="scope.row.user.level===3">中批发</template>
            <template v-if="scope.row.user.level===4">小批发</template>
            <template v-if="scope.row.user.level===5">团长</template>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template #default="scope">
            <!-- <el-button type="danger" size="small" @click="deleteClick(scope.row)">删除</el-button>
            <el-button type="primary" size="small" @click="editClick(scope.row)">编辑</el-button> -->
            <el-button type="primary" size="small" @click="moreClick(scope.row)">查看物流</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="timedPagination">
      <el-pagination
        v-model:current-page="prop.page"
        v-model:page-size="prop.limit"
        :total="prop.total"
        background
        layout="prev, pager, next"
        @current-change="handleCurrentChange">
      </el-pagination>
    </div>
    <!-- 新增or编辑分类 -->
    <el-dialog
      v-model="dialogVisible"
      width="1200"
      :before-close="dialogClose"
      title="订单详情"
      top="10vh"
      class="goodsDialog"
    >
      <div class="dialogContent">
        <div v-if="logisticsData" class="logisticsList">
          <div v-for="list,index of logisticsData" :key="index" class="list">
            <span class="time">{{ list.ftime }}:</span>
            <p>{{ list.context }}</p>
          </div>
          <div class="laiyuan">
            <span>信息来源：{{ formProp.deliver_company }}</span>
            <span>运单号: {{ formProp.deliver_sn }}</span>
          </div>
        </div>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <!-- <el-button :loading="loading" type="primary" @click="saveFun()">保存</el-button> -->
        </div>
      </template>
    </el-dialog>
  </div>
</template>


<script setup>
import { computed,ref,onMounted } from 'vue'
import { useChatInfoStore, useJobIDStore } from '@/store/index.js'
import { ElMessageBox, ElMessage } from 'element-plus'
import { postApi } from "@/api/api.js"
import elUploadOptionMultiple from '@/components/elUploadOptionMultiple.vue';
import moment from 'moment'
let prop = ref({
  sn: '',
  name: '',
  phone: '',
  status: '',
  create_time: '',
  user_id: '',
  userOption: [],
  page: 1,
  limit: 10,
  total: ''
})
let loading = ref(false)
let tableData = ref([])

// 查询商品
function init() {
  loading.value = true
  let obj = {
    sn: prop.value.sn,
    name: prop.value.name,
    phone: prop.value.phone,
    status: prop.value.status,
    create_time: prop.value.create_time,
    user_id: prop.value.user_id,
    page: prop.value.page,
    limit: prop.value.limit
  }
  postApi('/mall.order/index', obj).then(res => {
    loading.value = false
    tableData.value = res.data
    prop.value.total = res.count
  }).catch(err => {
    loading.value = false
  })
}
function resetClick() { // 重置
  prop.value = {
    sn: '',
    name: '',
    phone: '',
    status: '',
    create_time: '',
    user_id: '',
    page: 1,
  }
  init()
}
function handleCurrentChange(val){
  prop.value.page = val
  init()
}

// 详情
let dialogVisible = ref(false)
let formProp = ref({
  id: '',
  deliver_type: '',
  deliver_company: '',
  deliver_time: '',
  deliver_sn: '',
  status: ''
})

// 订单详情
let detailData=ref('')
function moreClick(row) {
  dialogVisible.value = true
  formProp.value.id = row.id
  logisticsFun()
}
let logisticsData = ref('')
function logisticsFun() {
  postApi('/mall.order/logistics',{id: formProp.value.id}).then(res => {
    if(res.code === 1){
      logisticsData.value = res.data
    }
    if(res.code === 0){
      logisticsData.value = ''
    }
  }).catch(err => {
  })
}

// 保存
function saveFun() {
  loading.value = true
  postApi('/mall.order/save', formProp.value).then(res => {
    if(res.code === 1){
      ElMessage({message: "操作成功",type: 'success'})
      logisticsFun()
    }
    loading.value = false
  }).catch(err => {
    loading.value = false
  })
}
// 关闭弹框
function dialogClose() {
  dialogVisible.value = false
}

onMounted(()=>{
  init()
  postApi('/agent.user/index').then(res => {
    if(res.code === 1){
      prop.value.userOption = res.data
    }
  }).catch(err => {
  })
})
</script>

<style lang="scss" scoped>
.apption{
  padding: 20px;
  height: 100vh;
  .topBox{
    position: relative;
    background-color: #fff;
    border-radius: 12px;
    padding: 20px 20px 10px 20px;
    margin: 20px 0;
    .searchTop{
      display: flex;
      justify-content: space-between;
      .left{
        width: calc(100% - 260px);
        display: flex;
        align-items: center;
        flex-wrap: wrap;
      }
      .right{
        width: 260px;
      }
    }
  }
  .topBut{
    cursor: pointer;
    position: absolute;
    right: 20px;
    top: 30px;
    z-index: 9;
  }
  .classOption{
    display: flex;
    justify-content: space-between;
    .oneClass{
      width: 32%;
      padding: 10px 16px;
      background: #FFFFFF;
      border-radius: 5rpx 5rpx 5rpx 5rpx;
      box-sizing: border-box;
    }
    .twoClass{
      width: 32%;
      padding: 10px 16px;
      background: #FFFFFF;
      border-radius: 5rpx 5rpx 5rpx 5rpx;
      box-sizing: border-box;
    }
    .threeClass{
      width: 32%;
      padding: 10px 16px;
      background: #FFFFFF;
      border-radius: 5rpx 5rpx 5rpx 5rpx;
      box-sizing: border-box;
    }
    .list{
      cursor: pointer;
      padding: 0 13px;
      margin-bottom: 8px;
      height: 36px;
      background: #F6F6F6;
      border-radius: 4px 4px 4px 4px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .el-icon{
        margin-left: 4px;
      }
      .deleteIco{
        cursor: pointer;
        margin-right: 4px;
      }
    }
    .active{
      background: #000000;
      border-radius: 4px 4px 4px 4px;
      color: #FFFFFF;
      .el-icon{
        color: #FFFFFF;
      }
      .deleteIco{
        color: #FFFFFF;
      }
    }
    .title{
      margin-bottom: 8px;
      display: flex;
      align-items: center;
      font-weight: bold;
      font-size: 14px;
      color: #BA9763;
      .el-icon{
        width: 36px;
        height: 36px;
        background: #F6F6F6;
        border-radius: 5px 5px 5px 5px;
        color: #666;
        font-size: 16px;
        margin-right: 4px;
      }
    }
    .addBut{
      height: 36px;
      line-height: 36px;
      text-align: center;
      display: block;
      border-radius: 4px 4px 4px 4px;
      border: 1px solid #F6F6F6;
      font-weight: 400;
      font-size: 14px;
      color: #000000;
    }
  }
  .pageTitle{
    margin-bottom: 10px;
    font-weight: 700;
    font-size: 16px;
    color: rgb(16, 16, 16);
  }
  .tableClass{
    margin-bottom: 20px;
  }
}
::v-deep .goodsDialog{
  background: rgba(245,245,245,1)!important;
}
.dialogContent{
  background: rgba(245,245,245,1)!important;
  ::v-deep .el-form-item__content{
    width: 190px;
  }
  .goodsMore{
    display: flex;
    justify-content: space-between;
    padding: 10px;
    margin-bottom: 10px;
    background: #fff;
    border-radius: 5px;
    .el-image{
      width: 160px;
      height: 160px;
    }
    .right{
      width: calc(100% - 180px);
      .name{
        margin-bottom: 20px;
        font-size: 14px;
        font-weight: bold;
      }
      .formText{
        span{
          margin-top: 10px;
          min-width: 180px;
          display: inline-block;
        }
      }
    }
  }
  .information{
    position: relative;
    padding: 10px;
    margin-bottom: 10px;
    background: #fff;
    border-radius: 5px;
    .saveBut{
      position: absolute;
      right: 20px;
      bottom: 20px;
    }
  }
  .logisticsList{
    padding: 10px;
    margin-bottom: 10px;
    background: #fff;
    border-radius: 5px;
    .list{
      margin-bottom: 10px;
      display: flex;
      line-height: 18px;
      .time{
        margin-right: 10px;
        text-align: right;
        display: inline-block;
        width: 160px;
      }
      p{
        width: calc(100% - 170px);
      }
    }
    .laiyuan{
      padding: 10px;
      background: rgba(230,230,230,1);
      text-align: center;
      span{
        margin-right: 20px;
      }
    }
  }
}
</style>
